<template>

  <el-dialog
    title="分配角色"
    :visible="dialogVisible"
    width="30%"
  >
    <el-checkbox-group v-model="checkList">
      <el-checkbox
        v-for="item in list"
        :key="item.id"
        :label="item.id"
      >
        <div class="roleName">
          {{ item.name }}
        </div>
      </el-checkbox>

    </el-checkbox-group>

    <template #footer>
      <el-row justify="center" type="flex">
        <el-button size="small" type="primary" @click="btnOK">确定</el-button>
        <el-button size="small" @click="btnCancel">取消</el-button>
      </el-row>
    </template>
  </el-dialog>

</template>

<script>
import { getRoleList } from '@/api/setting'
import { logoutdata } from '@/api/user'
import { assignRole } from '@/api/employees'
export default {
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    employeeId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      // 全部角色
      list: [],
      //   以勾选的函数
      checkList: []
    }
  },
  created() {
    this.getRoleList()
  },
  methods: {
    async getRoleList() {
      const { rows } = await getRoleList({ page: 1, pagesize: 999 })
      //   console.log(rows)
      this.list = rows
    //   console.log(this.list)
    },
    async getUserDetail(id) {
      const res = await logoutdata(id)
      //   console.log(res)
      this.checkList = [...res.roleIds]
    },
    async btnOK() {
    //   console.log(this.employeeId)
      await assignRole({
        id: this.employeeId,
        roleIds: this.checkList
      })

      //   console.log(res2)
      // 确定
      this.$message.success('请求数据成功')
      this.$emit('update:dialogVisible', false)
    },
    btnCancel() {
      this.$emit('update:dialogVisible', false)
    }
  }
}
</script>

<style>

</style>
